package yt.kpool.activity.personal;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.litepal.crud.DataSupport;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import yt.kpool.R;
import yt.kpool.activity.miner.AddMinerRemarkActivity;
import yt.kpool.base.BaseApplication;
import yt.kpool.bean.FastLookAccountBean;
import yt.kpool.util.SPUtil;
import yt.kpool.util.TitleControl;
import yt.kpool.util.ToastUtil;
import yt.kpool.view.AutoTextView;
import yt.kpool.view.dialog.LoadingDialog;

/**
 * 只读页面账号详情
 */
public class FastLookUserDetailActivity extends AppCompatActivity {

    /**
     * 跳转方法
     *
     * @param mactivity
     * @param Name      挖币账户
     * @param Remark    备注
     * @param Link      链接
     */
    public static void start(Activity mactivity, String Name, String Remark, String Link) {
        Intent intent = new Intent(mactivity, FastLookUserDetailActivity.class);
        intent.putExtra("Name", Name);
        intent.putExtra("Remark", Remark);
        intent.putExtra("Link", Link);
        mactivity.startActivity(intent);
    }

    public String getName() {
        return getIntent().getStringExtra("Name");
    }

    public String getRemark() {
        return getIntent().getStringExtra("Remark");
    }

    public String getLink() {
        return getIntent().getStringExtra("Link");
    }

    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_remark)
    TextView tv_remark;
    @BindView(R.id.tv_link)
    TextView tv_link;

    @BindView(R.id.btn_del)
    Button btn_del;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fast_look_user_detail);
        ButterKnife.bind(this);
        initTitle();
        SPUtil spUtil = new SPUtil(this, BaseApplication.KEYLOGIN);
        String name = spUtil.getString(BaseApplication.ChildAccountName, "");
        if (name.equals(getName()))
        {
            btn_del.setVisibility(View.GONE);
        }
    }

    private void initTitle() {
        TitleControl titleControl = new TitleControl(this);
        titleControl.setTitle(getName() + "(只读界面)");
        tv_name.setText(getName());
        tv_remark.setText(getRemark());
        tv_link.setText(getLink());
    }

    @OnClick({R.id.btn_copy, R.id.btn_del})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_copy://复制
                ClipboardManager cmb = (ClipboardManager) this.getSystemService(CLIPBOARD_SERVICE);
                cmb.setText(tv_link.getText().toString().trim());
                ToastUtil.showToast(this, "链接已复制到剪贴板");
                break;
            case R.id.btn_del://删除
                AlertDialog.Builder builder=new AlertDialog.Builder(FastLookUserDetailActivity.this);
                builder.setTitle("提示").setCancelable(false).setMessage("确定删除只读页面链接 "+getName()+" ？").setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                        DataSupport.deleteAll(FastLookAccountBean.class, "name = ? ",getName());
                        dialogInterface.dismiss();
                        finish();
                    }
                });
                builder.create().show();
                break;

        }
    }

}
